import json

from django.http import JsonResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt


def index(request):
    context = {}
    context['title'] = 'Stock Prediction'
    return render(request, 'index.html', context)


@csrf_exempt
def login(request):
    response = {'code': 200, 'isLogin': True, 'data': {'token': 'Hello World!'}}
    return JsonResponse(response)


@csrf_exempt
def getUserPerm(request):
    data = {}
    data['nickname'] = "admin"
    data['createTime'] = "2024-01-08 15:01:51"
    data['email'] = "123456@it.com"
    data[
        'avatarUrl'] = "https://ts1.cn.mm.bing.net/th/id/R-C.c066d1c3995a1ab81b8ae8b7f89b89a0?rik=oUBe3GQHGUvy4Q&riu=http%3a%2f%2fimg.touxiangwu.com%2fuploads%2fallimg%2f2022053117%2fn1pifhb1jid.jpg&ehk=2qPQHO7PzcYvcekfNhfZQX%2bQL5b5RLoPWki7yDndpk4%3d&risl=&pid=ImgRaw&r=0"
    data["roleColeList"] = ["super_admin"]
    data["sex"] = 1
    data["sexName"] = "男"
    data["username"] = "admin"
    data["userId"] = 1
    data["phone"] = 13812831298

    treeData1 = {"menuId": 1, "parentId": 0, "title": "首页", "icon": "Odometer", "children": [],
                 "component": "dashboard/index", "sort": 1, "isShow": True, "isShowBreadCrumb": True, "parentName": "",
                 "permList": [], "path": "/", "isHasPerm": True, "redirect": "",
                 "meta": {"isParentView": True, "sort": 1, "title": "首页", "isShow": True, "isShowBreadCrumb": True,
                          "icon": "Odometer", }}

    treeData2 = {"menuId": 2, "parentId": 0, "title": "LSTM预测", "icon": "DataAnalysis", "children": [],
                 "component": "lstm/index", "sort": 2, "isShow": True, "isShowBreadCrumb": True, "parentName": "",
                 "permList": [], "path": "/lstm", "isHasPerm": True, "redirect": "",
                 "meta": {"isParentView": True, "sort": 2, "title": "LSTM预测", "isShow": True, "isShowBreadCrumb": True,
                          "icon": "DataAnalysis", }}

    treeData3 = {"menuId": 3, "parentId": 0, "title": "情绪分析预测", "icon": "DataAnalysis", "children": [],
                 "component": "sentiment_analysis/index", "sort": 3, "isShow": True, "isShowBreadCrumb": True, "parentName": "",
                 "permList": [], "path": "/sentiment_analysis", "isHasPerm": True, "redirect": "",
                 "meta": {"isParentView": True, "sort": 3, "title": "情绪分析预测", "isShow": True, "isShowBreadCrumb": True,
                          "icon": "DataAnalysis", }}

    treeData4 = {"menuId": 4, "parentId": 0, "title": "语义分析预测", "icon": "DataAnalysis", "children": [],
                 "component": "srl/index", "sort": 4, "isShow": True, "isShowBreadCrumb": True, "parentName": "",
                 "permList": [], "path": "/srl", "isHasPerm": True, "redirect": "",
                 "meta": {"isParentView": True, "sort": 4, "title": "语义分析预测", "isShow": True, "isShowBreadCrumb": True,
                          "icon": "DataAnalysis", }}

    treeData5 = {"menuId": 5, "parentId": 0, "title": "综合预测", "icon": "DataAnalysis", "children": [],
                 "component": "comprehensive/index", "sort": 5, "isShow": True, "isShowBreadCrumb": True, "parentName": "",
                 "permList": [], "path": "/comprehensive", "isHasPerm": True, "redirect": "",
                 "meta": {"isParentView": True, "sort": 5, "title": "综合预测", "isShow": True, "isShowBreadCrumb": True,
                          "icon": "DataAnalysis", }}

    data['permissionTreeList'] = [treeData1, treeData2, treeData3, treeData4, treeData5]
    response = {'code': 200, 'data': data}
    return JsonResponse(response)
